package com.ruoyi.project.system.controller;

import java.util.List;

import com.ruoyi.project.common.CommonController;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysMomentFile;
import com.ruoyi.project.system.service.ISysMomentFileService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 精彩瞬间文件Controller
 *
 * @author jjp
 * @date 2020-04-14
 */
@RestController
@Api(description = "平台精彩瞬间文件")
@RequestMapping("/system/file")
public class SysMomentFileController extends BaseController {
    @Autowired
    private ISysMomentFileService sysMomentFileService;

    @Autowired
    private CommonController commonController;

    /**
     * 查询精彩瞬间文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMomentFile sysMomentFile) {
        startPage();
        List<SysMomentFile> list = sysMomentFileService.selectSysMomentFileList(sysMomentFile);
        return getDataTable(list);
    }


    /**
     * 获取精彩瞬间文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return AjaxResult.success(sysMomentFileService.selectSysMomentFileById(fileId));
    }

    /**
     * 新增精彩瞬间文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "精彩瞬间文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMomentFile sysMomentFile) {
        return toAjax(sysMomentFileService.insertSysMomentFile(sysMomentFile));
    }

    /**
     * 修改精彩瞬间文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "精彩瞬间文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMomentFile sysMomentFile) {
        return toAjax(sysMomentFileService.updateSysMomentFile(sysMomentFile));
    }

    /**
     * 删除精彩瞬间文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "精彩瞬间文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds) {
        return toAjax(sysMomentFileService.deleteSysMomentFileByIds(fileIds));
    }

}
